var specName_flag=true;
var specvNames_flag=true;

function specName_validata(){
	
	var specName=$("#specName");
	
	if(!ge_two_letters_regex.test(specName.val())){
        specName_flag=false;
		$("#specName_info").html("规格名称必须大于2个非空白字符！");
		return;
	}

	var project_path=$("#form1").attr("project_path");
	
	$.ajax({
		   type: "get",
		   url: project_path+"/spec/isExistsBySpecName",
		   data:{specName:specName.val()},
		   success: function(isExists){
		     if(isExists){
                 specName_flag=false;
		 		$("#specName_info").html("规格名称已经存在！");
		     }else{
                 specName_flag=true;
		 		$("#specName_info").html("");
		     }
		   }
	});
}

function specvName_validata(element) {

	var id_index=$(element).attr("index");
	var specvName=$("#specvName_"+id_index);

    if(!ge_two_letters_regex.test(specvName.val())){
        $("#specvName_info_"+id_index).html("内容名称必须大于2个非空白字符！");
        return false;
    }else{
        $("#specvName_info_"+id_index).html("");
        return true;
	}

}

function specvNames_validata(){
	var specvNames=$("[name='specvNames']");
    specvNames_flag=true;
	$(specvNames).each(function (index,item) {
        specvNames_flag=specvNames_flag&specvName_validata(item);
    });
}

$("#specName").blur(function(){
    specName_validata();
});

$("#btn_submit").click(function(){

    specName_validata();
    specvNames_validata()

	if(specName_flag&&specvNames_flag)
		$("#form1").submit();
});